package com.enjoyor.health.HGPT.core.service.impl;

import com.enjoyor.health.HGPT.core.dto.ReportUserDto;
import com.enjoyor.health.HGPT.core.entity.ReportRecord;
import com.enjoyor.health.HGPT.core.mapper.ReportRecordMapper;
import com.enjoyor.health.HGPT.core.service.IReportRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author enjoyor
 * @since 2023-10-18
 */
@Service
public class ReportRecordServiceImpl extends ServiceImpl<ReportRecordMapper, ReportRecord> implements IReportRecordService {

    @Autowired
    private ReportRecordMapper reportRecordMapper;

    @Override
    public List<ReportRecord> getReportRecordByOpenId(String openId, String version, Integer packageType) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("open_id", openId);
        map.put("version", version);
        map.put("package_type", packageType);
        return reportRecordMapper.getReportRecordByOpenId(map);
    }

    @Override
    public ReportRecord getReportRecordByOpenId(String openId) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("open_id", openId);
        return reportRecordMapper.getReportRecordByOpenIdSingle(map);
    }

    @Override
    public ReportRecord getRobotReportRecordByOpenId(String openId, String version, Integer type) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("open_id", openId);
        map.put("version", version);
        map.put("type", type);
        return reportRecordMapper.getRobotReportRecordByOpenIdSingle(map);
    }

    @Override
    public ReportUserDto getReportByUser(String openId, String version, Integer packageType) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("open_id", openId);
        map.put("version", version);
        map.put("package_type", packageType);
        return reportRecordMapper.getReportByUserV2(map);
    }

    @Override
    public ReportUserDto getReportByUser(String openId, String version) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("open_id", openId);
        map.put("version", version);
        return reportRecordMapper.getReportByUser(map);
    }

    @Override
    public ReportRecord getLatestVersion(String openId) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("open_id", openId);
        return reportRecordMapper.getLatestVersion(map);
    }

    @Override
    public ReportRecord getLatestVersionByType(String openId, Integer reportType) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("open_id", openId);
        map.put("report_type", reportType);
        return reportRecordMapper.getLatestVersionByType(map);
    }

}
